Skip to main content

Rasterex Database server back-end

You can get our db back-end from our github here.

DB back-end

https://github.com/Rasterex-Software/dbbackend

rx-back-end

Backend service for authentication, web socket, user management, projects, and annotations.

Set up viewer to use db

In order for the Rasterex Web Viewer to get access to your db back end you will need to provide a valid URL to the db back-end server in the assets/scripts/rxconfig.js file

The line to change in rxconfig.js is this line. This will default point to the official Rasterex db back-end server.

   var apiBaseURL = "https://rxserver.rasterex.com/";
//change to your own server location

var apiBaseURL = "https://myserver.mydomain.com/";


Quick Start Checklist

Follow these steps to set up the rx-back-end for the first time:

This db-backend requires Node.js and PostgreSQL to be installed on the server.

  1. Install prerequisites

  2. Acquire and prepare project files

    • Option A: Clone the repository (developer setup)
      git clone <repo-url>
      cd rx-back-end
    • Option B: Copy files to the server (deployment setup)
      • Create a folder on the server, e.g. C:\rx-back-end (Windows) or /opt/rx-back-end (Linux).
      • Copy the following into that folder:
        • app/ (source files: controllers/, models/, routes/, etc.)
        • server.js
        • seed.js
        • swagger.js
        • package.json
        • package-lock.json
        • Scripts/ (SQL setup scripts)
        • .env.example
        • docs/ (documentation)
  3. Install dependencies
    Open a terminal/command prompt, navigate to the folder where the files are located, and run:

    npm install
  4. Configure environment variables

    • Copy .env.example to .env

    • Update database credentials, server port, and CORS origin

    • On Linux/Mac:

      cp .env.example .env
    • On Windows (PowerShell/Command Prompt):

      copy .env.example .env

    Example .env values:

    # Database configuration
    DB_HOST=localhost
    DB_PORT=5432
    DB_USER=postgres
    DB_PASSWORD=postgres
    DB_NAME=rxdb

    # Server port
    PORT=8080

    # Allowed origin (CORS)
    # Set this to the frontend domain that will connect to the API.
    # For development, use http://localhost:4200
    ALLOWED_ORIGIN=https://myserver.mydomain.com

  5. Set up the database

    • Run provided scripts from the Scripts/ folder:

      • Windows: ./Scripts/setup_db.bat
      • Linux/Mac: ./Scripts/setup_db.sh
    • Or run SQL manually with psql:

      psql -U <username> -d rxdb -f Scripts/create_tables.sql
      psql -U <username> -d rxdb -f Scripts/schema.sql
      psql -U <username> -d rxdb -f Scripts/insert_data.sql
    • To reset the database:

      • Windows:
        ./Scripts/drop_tables.bat
      • Manual:
        psql -U <username> -d rxdb -f Scripts/drop_tables.sql
  6. Start the backend server

    npm start
  7. (Optional) Run as a service with PM2

    PM2 is a process manager for Node.js. It keeps the backend running in the background, restarts it if it crashes, and can auto-start on boot.

    • Install PM2 globally:
      npm install -g pm2
      pm2 -v
    • Start the service:
      pm2 start server.js --name "rx-backend"
    • Monitor logs and processes:
      pm2 ps
      pm2 logs rx-backend
    • Stop or restart:
      pm2 stop rx-backend
      pm2 restart rx-backend
    • Enable auto-start on reboot:
      pm2 startup
      pm2 save

Troubleshooting

  • Port already in use → Change PORT in .env.
  • DB connection errors → Verify PostgreSQL is running, .env values are correct.
  • Swagger not loading → Ensure the server runs without errors (npm start).
  • CORS issues → Update ALLOWED_ORIGIN in .env to match your frontend domain.